#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# ======================================================
# @File:      : theme
# @Author     : forward_huan
# @Date       : 2025/9/13 7:43
# @Desc       :
# ======================================================
import os
from typing import Dict, List, Tuple

CATEGORICAL_DATA = {
    "basic": "通用",
    "study": "学习",
    "office": "办公",
    "entertainment": "娱乐",
    "lifestyle": "生活",
}

theme_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "theme")


class ThemeModel(object):
    def __init__(self, theme_path, classify_name):
        self.file_name = os.path.basename(theme_path)
        self.classify_name_en = classify_name
        self.classify_name_ch = CATEGORICAL_DATA.get(classify_name, "")
        self._parse(theme_path)

    def _parse(self, theme_path):
        with open(theme_path, "r", encoding="utf-8") as f:
            content = f.readlines()
            self.english_name = (content[1]).replace("英文名称:", "").strip()
            self.china_name = (content[2]).replace("中文名称:", "").strip()
            self.desc = (content[3]).replace("应用介绍:", "").strip()
            self.style = "".join(content[5:]).strip()

    def show_name(self):
        return "{}({})".format(self.english_name, self.china_name)

    def __str__(self):
        return "{}({})".format(self.english_name, self.china_name)


def get_theme_model_data():
    """获取theme对象"""
    theme_model_data: Dict[str, List[ThemeModel]] = {}
    for classify_name in CATEGORICAL_DATA:
        theme_model_data[classify_name] = []
        for name in os.listdir(os.path.join(theme_dir, classify_name)):
            if not name.startswith("theme"):
                continue
            file_path = os.path.join(theme_dir, classify_name, name)
            theme_model_data[classify_name].append(ThemeModel(file_path, classify_name))
    return theme_model_data


def get_theme_data():
    """获取所有主题的英文名称"""
    theme_data: List[Tuple[str, str, str]] = []
    for models in get_theme_model_data().values():
        for model in models:
            theme_data.append((model.show_name(), model.desc, model.style))
    return theme_data


def get_theme_en_data():
    """获取所有主题的英文名称"""
    theme_data: List[Tuple[str, str, str]] = []
    for models in get_theme_model_data().values():
        for model in models:
            theme_data.append((model.english_name, model.desc, model.style))
    return theme_data


def get_theme_ch_data():
    """获取所有主题的英文名称"""
    theme_data: List[Tuple[str, str, str]] = []
    for models in get_theme_model_data().values():
        for model in models:
            theme_data.append((model.china_name, model.desc, model.style))
    return theme_data
